
package net.swa.dewei.web.action;

import java.util.Map;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import net.swa.dewei.beans.entity.OneCard;
import net.swa.dewei.service.OneCardService;
import net.swa.system.service.ICommonService;
import net.swa.system.util.annotation.Log;
import net.swa.system.web.action.AbstractBaseAction;
import net.swa.util.DateUtils;
import net.swa.util.JsonResult;

/**电池信息表 Action**/
public class OneCardAction extends AbstractBaseAction
{
    private static final long serialVersionUID = -9167064623097370397L;

    private final Logger log = Logger.getLogger(OneCardAction.class);

    /** 公用方法接口 */
    private ICommonService commonService;

    private OneCardService oneCardService;

    //实体类id
    private Long id;

    //广告实体类
    private OneCard model;

    //id集合
    private Long[] ids;

    /**初始化分页查询**/
    @Log(description = "进入一卡通分页查询")
    public String listPage()
    {
        return "listPage";
    }

    public String queryPage() throws Exception
    {
        currentPage = currentPage == 0 ? 1 : currentPage;
        pageSize = pageSize == 0 ? 20 : pageSize;
        JsonResult<OneCard> json = null;
        String[] attrNames = new String[] {};
        String[] attrOperator = new String[] {};
        Object[] attrValues = new Object[] {};
        //支持多种条件查询分页便于扩展
        json = oneCardService.queryPage(attrNames, attrOperator, attrValues, currentPage, pageSize, orderBy, orderType);
        json.setCurrentPage(currentPage);
        outJson(json);
        return null;
    }

    /**去新增或者修改页面**/
    @Log(description = "去新增或者修改一卡通页面")
    public String toAddOneCard() throws Exception
    {
        log.debug("编辑广告信息");
        if (null != id)
        {
            model = oneCardService.queryById(id);
        }
        else
        {
            model = new OneCard();
        }
        return "toAddAd";
    }

    /**新增或者修改**/
    @Log(description = "新增或者修改一卡通")
    public String saveOneCard() throws Exception
    {
        Map<String, Object> map;
        if (null == model.getId())
        {
            log.debug("新增：" + model);
            model.setCrateDate(DateUtils.getCurrDate(null));
            map = oneCardService.add(model);
        }
        else
        {
            log.debug("修改：" + model);
            model.setUpdateDate(DateUtils.getCurrDate(null));
            map = oneCardService.update(model);
        }
        if (null == map)
        {
            outError("error");
        }
        else
        {
            outJson(map);
        }
        return null;
    }

    /** * 删除方法**/
    @Log(description = "删除一卡通")
    public String delete() throws Exception
    {
        oneCardService.delete(ids);
        outSuccess();
        return null;
    }

    @Required
    @Resource
    public void setCommonService(ICommonService commonService)
    {
        this.commonService = commonService;
    }

    @Required
    @Resource
    public void setOneCard(OneCardService oneCardService)
    {
        this.oneCardService = oneCardService;
    }

    public Long getId()
    {

        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public Long[] getIds()
    {
        return ids;
    }

    public void setIds(Long[] ids)
    {
        this.ids = ids;
    }

    public ICommonService getCommonService()
    {
        return commonService;
    }

    public OneCard getModel()
    {
        return model;
    }

    public void setModel(OneCard model)
    {
        this.model = model;
    }
}
